<?php

class FraisController extends Zend_Controller_Action {

    public function init() {
        if (!Zend_Auth::getInstance()->hasIdentity()) {
            $this->_redirect('/authentification/login');
        }
    }

    public function indexAction() {
        // action body
    }

    public function listerfAction() {
        $lesFraisForfait = new Application_Model_DbTable_FraisForfait();
        $this->view->lesFraisForfait = $lesFraisForfait->fetchAll();
        $this->view->setEscape('htmlentities');
        $this->view->setEncoding('ISO-8859-1');
    }

    public function gererfAction() {
        $lesFraisForfait = new Application_Model_DbTable_FraisForfait();
        $this->view->lesFraisForfait = $lesFraisForfait->fetchAll();
        $this->view->setEscape('htmlentities');
        $this->view->setEncoding('ISO-8859-1');
    }

    public function modifierfAction() {
        $form = new Application_Form_Frais();
        $form->envoyer->setLabel('sauvegarder');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $id = $form->getValue('id');
                $libelle = $form->getValue('libelle');
                $montant = $form->getValue('montant');
                $lesFraisForfait = new Application_Model_DbTable_FraisForfait();
                $lesFraisForfait->modifierFraisForfait($id, $libelle, $montant);
                $this->_helper->redirector('gererf');
            } else {
                $form->populate($formData);
            }
        } else {
            $id = $this->_getParam('id', 0);
            $lesFraisForfait = new Application_Model_DbTable_FraisForfait();
            $form->populate($lesFraisForfait->obtenirFraisForfait($id));
        }
    }

}
